package controller

import (
	"encoding/json"
	"fmt"
	"fx_swift_schedule/api"
	"fx_swift_schedule/internal/service"
	"fx_swift_schedule/pkg/code"
	"fx_swift_schedule/pkg/internalerrors"
	"fx_swift_schedule/pkg/logger"
	"github.com/gin-gonic/gin"
	"github.com/gogf/gf/v2/frame/g"
	"io/ioutil"
	"net/http"
)

// created状态的回调
func CustomerCreatedCallBack(c *gin.Context) {
	//req := &api.MerVACallBackReq{}
	body, err := ioutil.ReadAll(c.Request.Body)

	str := string(body)
	g.Dump("回调参数打印：", str)
	fmt.Println(err)
}

// updated状态的回调
func CustomerUpdatedCallBack(c *gin.Context) {
	//req := &api.MerVACallBackReq{}
	body, err := ioutil.ReadAll(c.Request.Body)

	str := string(body)
	g.Dump("updated回调参数打印：", str)
	fmt.Println(err)
}

// updated状态的回调
func CustomerCompletedCallBack(c *gin.Context) {
	req := &api.CustomerCallBackReq{}
	body, err := ioutil.ReadAll(c.Request.Body)
	g.Dump("测试打印：", string(body))
	err = json.Unmarshal(body, &req)
	if err != nil {
		logger.SugarLogger.Errorf("json转换:%w", err)
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}

	err = service.NewComplyCallBackSrv().CustomerCompletedCallBack(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, nil)
	}
}
